-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build: Replace global with globalThis [WIP] #19386
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Conflicts: # code/addons/backgrounds/package.json # code/addons/highlight/package.json # code/addons/interactions/package.json # code/addons/jest/package.json # code/addons/links/package.json # code/addons/measure/package.json # code/addons/storyshots/storyshots-core/src/api/index.ts # code/addons/viewport/package.json # code/examples/cra-ts-kitchen-sink/package.json # code/frameworks/ember/package.json # code/frameworks/react-vite/package.json # code/frameworks/vue3-vite/package.json # code/lib/addons/package.json # code/lib/addons/src/main.ts # code/lib/channel-postmessage/package.json # code/lib/channel-websocket/package.json # code/lib/core-client/package.json # code/lib/core-client/src/globals/globals.ts # code/lib/core-client/src/preview/start.ts # code/lib/instrumenter/package.json # code/lib/ui/src/components/sidebar/Search.tsx # code/lib/ui/src/index.tsx # code/renderers/html/package.json # code/renderers/preact/package.json # code/renderers/server/package.json # code/renderers/svelte/package.json # code/renderers/vue/package.json # code/renderers/vue/src/globals.ts # code/renderers/vue3/package.json # code/renderers/vue3/src/globals.ts # code/renderers/web-components/package.json # code/renderers/web-components/src/index.ts # code/yarn.lock
# Conflicts: # code/addons/actions/src/runtime/withActions.ts # code/addons/actions/template/stories/parameters.stories.ts # code/addons/backgrounds/package.json # code/addons/controls/template/stories/basics.stories.ts # code/addons/controls/template/stories/conditional.stories.ts # code/addons/controls/template/stories/disable.stories.ts # code/addons/controls/template/stories/filters.stories.ts # code/addons/controls/template/stories/issues.stories.ts # code/addons/controls/template/stories/matchers.stories.ts # code/addons/controls/template/stories/sorting.stories.ts # code/addons/docs/package.json # code/addons/docs/src/preset.ts # code/addons/docs/src/typings.d.ts # code/addons/highlight/package.json # code/addons/interactions/package.json # code/addons/interactions/template/stories/basics.stories.ts # code/addons/jest/package.json # code/addons/links/package.json # code/addons/measure/package.json # code/addons/outline/package.json # code/addons/storyshots/storyshots-core/package.json # code/addons/storyshots/storyshots-core/src/frameworks/configure.ts # code/addons/storyshots/storyshots-core/src/frameworks/svelte/renderTree.ts # code/addons/toolbars/template/stories/globals.stories.ts # code/addons/viewport/package.json # code/examples/angular-cli/package.json # code/examples/angular-cli/src/cssWarning.ts # code/examples/html-kitchen-sink/package.json # code/examples/html-kitchen-sink/stories/button.stories.js # code/examples/html-kitchen-sink/stories/from-essentials/Header.ts # code/examples/html-kitchen-sink/stories/from-essentials/Page.ts # code/examples/html-kitchen-sink/typings.d.ts # code/examples/official-storybook/head-warning.js # code/examples/official-storybook/package.json # code/examples/preact-kitchen-sink/package.json # code/examples/react-ts/.storybook/main.ts # code/examples/react-ts/src/button.tsx # code/examples/svelte-kitchen-sink/package.json # code/examples/svelte-kitchen-sink/src/components/Button.test.js # code/examples/web-components-kitchen-sink/package.json # code/frameworks/angular/package.json # code/frameworks/angular/setup-jest.ts # code/frameworks/angular/src/client/angular/helpers.ts # code/frameworks/angular/src/typings.d.ts # code/frameworks/ember/package.json # code/frameworks/ember/src/client/preview/render.ts # code/frameworks/html-webpack5/package.json # code/frameworks/nextjs/template/cli/ts/Button.tsx # code/frameworks/react-webpack5/src/typings.d.ts # code/frameworks/vue-webpack5/src/typings.d.ts # code/lib/addons/package.json # code/lib/addons/src/hooks.ts # code/lib/addons/src/main.ts # code/lib/api/src/lib/shortcut.ts # code/lib/api/src/lib/stories.ts # code/lib/api/src/modules/refs.ts # code/lib/api/src/modules/release-notes.ts # code/lib/api/src/modules/shortcuts.ts # code/lib/api/src/modules/url.ts # code/lib/api/src/modules/versions.ts # code/lib/api/src/tests/shortcut.test.js # code/lib/api/src/tests/stories.test.ts # code/lib/channel-postmessage/package.json # code/lib/channel-websocket/package.json # code/lib/client-api/src/ClientApi.ts # code/lib/client-api/src/StoryStoreFacade.ts # code/lib/client-api/src/queryparams.ts # code/lib/core-client/package.json # code/lib/core-client/src/manager/index.ts # code/lib/core-client/src/manager/provider.ts # code/lib/core-client/src/start.ts # code/lib/core-client/src/typings.d.ts # code/lib/core-server/src/typings.d.ts # code/lib/instrumenter/package.json # code/lib/preview-web/src/Preview.tsx # code/lib/preview-web/src/PreviewWeb.tsx # code/lib/preview-web/src/UrlStore.ts # code/lib/preview-web/src/render/StoryRender.ts # code/lib/router/src/router.tsx # code/lib/store/src/csf/prepareStory.ts # code/lib/store/template/stories/argTypes.stories.ts # code/lib/store/template/stories/args.stories.ts # code/lib/store/template/stories/decorators.stories.ts # code/lib/store/template/stories/globals.stories.ts # code/lib/store/template/stories/hooks.stories.ts # code/lib/store/template/stories/loaders.stories.ts # code/lib/store/template/stories/parameters.stories.ts # code/lib/store/template/stories/rendering.stories.ts # code/lib/theming/src/typings.d.ts # code/lib/ui/src/components/sidebar/Search.tsx # code/presets/react-webpack/src/typings.d.ts # code/presets/server-webpack/package.json # code/renderers/html/package.json # code/renderers/preact/package.json # code/renderers/react/src/render.tsx # code/renderers/server/package.json # code/renderers/svelte/package.json # code/renderers/svelte/src/globals.ts # code/renderers/svelte/src/render.ts # code/renderers/vue/package.json # code/renderers/vue/template/components/index.js # code/renderers/vue3/package.json # code/renderers/web-components/package.json # code/renderers/web-components/src/docs/__testfixtures__/lit-element-demo-card/input.js # code/renderers/web-components/src/globals.ts # code/renderers/web-components/src/index.ts # code/renderers/web-components/src/render.ts # code/renderers/web-components/template/components/index.js # code/ui/blocks/src/blocks/DocsContainer.tsx # code/ui/blocks/src/blocks/DocsContext.ts # code/ui/blocks/src/components/Preview.stories.tsx # code/ui/blocks/src/components/Story.tsx # code/ui/blocks/src/typings.d.ts # code/ui/manager/src/components/layout/app.mockdata.tsx # code/ui/manager/src/components/sidebar/RefBlocks.tsx # code/ui/manager/src/components/sidebar/RefIndicator.tsx # code/ui/manager/src/components/sidebar/SearchResults.tsx # code/ui/manager/src/components/sidebar/useHighlighted.ts # code/ui/manager/src/components/sidebar/utils.ts # code/ui/manager/src/index.tsx # code/ui/manager/src/runtime.ts # code/ui/manager/src/settings/index.tsx # code/yarn.lock # scripts/.eslintrc.js
We were getting an old version via @types/webpack-virtual-modules
# Conflicts: # code/addons/backgrounds/package.json # code/addons/highlight/package.json # code/addons/interactions/package.json # code/addons/jest/package.json # code/addons/links/package.json # code/addons/measure/package.json # code/addons/outline/package.json # code/addons/viewport/package.json # code/frameworks/ember/package.json # code/frameworks/html-webpack5/package.json # code/lib/addons/package.json # code/lib/channel-postmessage/package.json # code/lib/channel-websocket/package.json # code/lib/core-client/package.json # code/lib/instrumenter/package.json # code/package.json # code/presets/server-webpack/package.json # code/renderers/html/package.json # code/renderers/preact/package.json # code/renderers/server/package.json # code/renderers/svelte/package.json # code/renderers/vue/package.json # code/renderers/vue3/package.json # code/renderers/web-components/package.json # code/yarn.lock
# Conflicts: # code/addons/a11y/src/a11yRunner.ts # code/addons/actions/src/decorator.ts # code/addons/backgrounds/package.json # code/addons/highlight/package.json # code/addons/highlight/src/preview.ts # code/addons/interactions/package.json # code/addons/jest/package.json # code/addons/links/package.json # code/addons/links/src/utils.ts # code/addons/measure/package.json # code/addons/outline/package.json # code/addons/storyshots/storyshots-core/src/api/index.ts # code/addons/viewport/package.json # code/frameworks/ember/package.json # code/frameworks/html-webpack5/package.json # code/lib/addons/package.json # code/lib/addons/src/typings.d.ts # code/lib/builder-webpack5/package.json # code/lib/builder-webpack5/templates/virtualModuleModernEntry.js.handlebars # code/lib/channel-postmessage/package.json # code/lib/channel-websocket/package.json # code/lib/client-api/package.json # code/lib/core-client/package.json # code/lib/instrumenter/package.json # code/lib/manager-api/src/lib/addons.ts # code/lib/manager-api/src/tests/stories.test.ts # code/lib/preview-api/src/modules/client-api/StoryStoreFacade.ts # code/lib/preview-api/src/modules/client-api/typings.d.ts # code/lib/preview-api/src/modules/core-client/start.ts # code/lib/preview-api/src/modules/preview-web/Preview.tsx # code/lib/preview-api/src/modules/preview-web/WebView.ts # code/lib/preview-api/src/modules/preview-web/simulate-pageload.test.ts # code/lib/preview-api/src/modules/store/typings.d.ts # code/lib/preview-web/package.json # code/lib/router/src/router.tsx # code/lib/store/package.json # code/presets/server-webpack/package.json # code/renderers/html/package.json # code/renderers/html/src/globals.ts # code/renderers/preact/package.json # code/renderers/server/package.json # code/renderers/svelte/package.json # code/renderers/vue/package.json # code/renderers/vue3/package.json # code/renderers/web-components/package.json # code/ui/.storybook/preview.tsx # code/ui/components/src/Loader/Loader.tsx # code/yarn.lock
IanVS
commented
Dec 1, 2022
@@ -333,7 +334,8 @@ export class Instrumenter { | |||
// returns the original result. | |||
track(method: string, fn: Function, args: any[], options: Options) { | |||
const storyId: StoryId = | |||
args?.[0]?.__storyId__ || global.window.__STORYBOOK_PREVIEW__?.urlStore?.selection?.storyId; | |||
args?.[0]?.__storyId__ || | |||
globalThis.__STORYBOOK_PREVIEW__?.selectionStore?.selection?.storyId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ndelangen this could be causing the issue I identified in discord.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue:
What I did
This removes the use of the
global
npm package, instead preferringglobalThis
, which works in all supported storybook environments. Besides removing an extra (and widespread) dependency, this also improves our typescript coverage, sinceglobal
did not have type definitions, butglobalThis
does. I also used module augmentation to add the types for the global values that storybook adds as well.The reason this is still WIP is that mocking
globalThis
in tests only works in jest 28+, so now that we've updated I can start working on the tests.There are also some type errors that I could use some help with. Some of them are new and result from having proper types for
globalThis
, and some are perhaps due to faulty types inglobalThis.d.ts
.How to test
If your answer is yes to any of these, please make sure to include it in your PR.